<template>
	<view class="ag_container">
		<p class="per_title">
			<span><i class="iconfont">&#xe63f;</i> 个人抄送方</span>
			<button size="mini" class="primay_btn" @click="confirm">确 定</button>
		</p>
		<uni-forms ref="ruleForm" :modelValue="ruleForm" :rules="rules" label-position="right" class="personal_form">
		<uni-forms-item  name="sendName" >
		<uni-easyinput v-model="ruleForm.sendName" type="text" placeholder="抄送人真实姓名" prefixIcon="person" suffixIcon="forward" @iconClick="iconClick" />
		</uni-forms-item>
		<uni-forms-item name="sendMobile" >
		<uni-easyinput v-model="ruleForm.sendMobile" type="text" placeholder="抄送人实名手机号" prefixIcon="phone" @iconClick="iconClick" />
		</uni-forms-item>
		</uni-forms>

		<!-- 提示 -->
		<p class="remark">请填写抄送人真实姓名和实名手机号码。抄送人可查阅、下载合同文件，最多可抄送给10位伙伴。</p>
	</view>
	</view>
</template>

<script>
	import {getCustomerPerson} from "@/api/ec/work/customer/customerPerson";
	import {addContractCopy} from "@/api/ec/work/contract/contract";
	export default {
		components: {
		},
		data() {
			return {
				ruleForm:{
					id: 0,
					sendCompany: "",
					sendMobile: "",
					sendName: "",
					senderType: 1,          
				},
				rules: {
					sendName: {rules:[{
						required: true,
						errorMessage: "请输入抄送人真实姓名",
						trigger: "blur"
					} ]},
					sendMobile: {rules:[{
						required: true,
						errorMessage: "请输入抄送人实名手机号",
						trigger: "blur"
					},
					 ]},
					},
				index:0,
				personalCopy:'',
			};
		},
		onLoad(option) {
		  if(option.ruleForm){
		  	this.ruleForm = JSON.parse(option.ruleForm)
			this.index = option.index
		  }
		  this.personalCopy = option.personalCopy
		  uni.$on('copyStaffData',data=>{
			  this.ruleForm = data
		  })
		},
		methods: {
			/** 快捷选择联系人 */
			iconClick(){
				uni.navigateTo({
					url:'/pages/sign/select/selectPersonal?personalCopy=' + true
				})
			},
			/**确认*/
			confirm(){
				this.$refs.ruleForm.validate((valid) => {
					if (valid) {
							return false;
					}else{
						// 返回指定页面 不刷新合同编号
						let pages = getCurrentPages();
						var num = pages.length
						//当前页面栈总数
						var backnum
						if(this.personalCopy){
							//需要返回的页数
							for(var i =0;i<num;i++){
								//循环找到指定页面路由所在的页数
								if(pages[i].route=='pages/sign/detail'){
									backnum=num-i-1
									//计算返回的层数，总数-指定页面页数-1
								}		
							}
						}else{
							//需要返回的页数
							for(var i =0;i<num;i++){
								//循环找到指定页面路由所在的页数
								if(pages[i].route=='pages/sign/sign'){
									backnum=num-i-1
									//计算返回的层数，总数-指定页面页数-1
								}		
							}
						}
						uni.navigateBack({
							delta:backnum //返回的页面数，如果 delta 大于现有页面数，则返回到首页。
						})
						uni.$emit('personalTableData',{ruleForm:this.ruleForm,index:this.index})
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	page {
		background: $uni-bg-color;
	}
	::v-deep .uni-forms-item__label{padding: 0;}
    ::v-deep .uni-forms-item .is-required{
    	display: none;
    }
	.remark {
		font-size: 24rpx;
		color: #999999;
		word-wrap:break-word;
		// white-space: pre-wrap;
	}

	.per_title {
		font-size: 30rpx;
		color: #666666;
		border-bottom: 1rpx solid #d3d3d3;
		padding-bottom: 12rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.iconfont {
			padding-right: 6rpx;
		}
	}
    .personal_form {
    	margin-top: 40rpx;
    	padding: 0 10rpx;
    }
	.ag_container {
		position: relative;
		padding:30rpx 40rpx 0;
	}
</style>
